/*
* $Id: TableDrawer.h 152 2010-09-23 18:28:55Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#ifndef _TABLE_DRAWER_H_
#define _TABLE_DRAWER_H_

#include "TableHeaderRow.h"
#include "TableCelRow.h"
#include "TableStructs.h"
#include "ResizeHelper.h"
#include "../Drawer.h"

class CTableHeader;

class CTableDrawer : public CDrawer
{
	int m_nPosYFirstCel;
	int m_nPosYFirstVisibleCel;
	CTableCelRow* m_pFirstVisibleRow;
	CTableCelRow* m_pSelectRow;
	CTableHeader* m_pCurResizeHeader;
	CTableCelRow* m_pCurResizeRow;
	bool m_bResizeHeader;
	bool m_bResizeRow;
	CResizeHelper m_resizeHelper;
	std::vector<CTableCelRow*> m_aCels;
	CTableHeaderRow m_HeaderRow;
public:
	CTableDrawer(IWnd* pParent);
	virtual ~CTableDrawer();
public:
	void InitTable();
	void ResetTable();
	void AddCelRow(CTableCelRow *row);
	tableHeader* AddHeader(const std::tstring& strName, int nId, TypeField::type type);
	void DeleteRow(int nRow);
	void DeleteRow(CTableCelRow* pRow);
	void SortColumn(int nColumn);
public:
	void SetFirstCelPosY(int pos);
	void SetPosX(int pos);
	void UpgradeFirstVisiblePosY(int newPos);
	void NormalizeHeader();
public:
	int GetHeightTable();
	int GetWidthTable();
public:
	bool IsSelectRow();
	CTableCelRow* GetSelectRow();
	int GetRowSelect();
	void SelectRow(CPoint point);
	void SelectRow(CTableCelRow* pRow);
	void SelectRow(int nRow);
public:
	CRect GetResizeHeaderRect();
	bool BeginResizeHeader(CPoint pos);
	void ResizeHeader(CSize size);
	void EndResizeHeader();
	bool IsResizeHeader();
	bool IsBeginResizeHeader(CPoint pos);
public:
	void GetResizeRowPosSize(int* nPos, int* nSize);
	bool IsBeginResizeRow(CPoint pos);
	bool IsResizeRow();
	bool BeginResizeRow(CPoint pos);
	void ResizeRow(int size);
	void EndResizeRow();
public:
	virtual void Paint(CDC* dc, CRect rect);
public:
	virtual bool IsValidDrawer(Drawer::typeDrawer nType);
};

#endif/*_TABLE_DRAWER_H_*/